/**
 * Spare.java
 * 
 * This class is a concrete handler in the Chain of Responsibility pattern. It
 * represents the second ball in a frame when it knocks down all the remaining
 * pins for that frame. The score returned by getCalculatedScore is the number
 * of pins knocked down for this ball plus the number of pins knocked by the
 * next ball if it was thrown yet.
 * 
 * @author Robert Yates
 */
public class Spare extends ScoreHandler {
	
	/**
	 * Construct a spare with a given score.
	 * 
	 * @param score		The original score of the ball.
	 */
	public Spare(int score) {
		setOriginalScore(score);
	}

	/**
	 * Returns the most accurate calculation of the score.
	 * 
	 * @return 		The original score plus any subsequent scores if they are 
	 *         		used to calculate this total score.
	 */
	@Override
	public int getCalculatedScore() {
		// A spare's calculated score is the original score plus the next
		// handler's original score if the next handler exists.
		int cummulativeScore = originalScore;
		if (nextHandler != null) {
			cummulativeScore += nextHandler.getOriginalScore();
		}
		return cummulativeScore;
	}
}
